using System;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using Microsoft.SharePoint;

namespace SharePointing.Features.Translation.EventReceivers
{

    public class CachedListEventReceiver : SPItemEventReceiver
    {
        public CachedListEventReceiver()
        {
        }

        /// <summary>
        /// This Event Reciever is for clearing out the Cache in Memory
        /// </summary>
        /// <param name="properties"></param>
        public override void ItemAdding(SPItemEventProperties properties)
        {
            base.ItemAdding(properties);
            try
            {
                SPSiteDataQuery q = new SPSiteDataQuery();
                Common.Utilities.ClearCache("listName");
            }
            catch (Exception ex)
            {
                // TODO: Add Error Handling ?? Should be a pretty safe Operation I would think...
            }
        }

        public override void ItemDeleting(SPItemEventProperties properties)
        {
            base.ItemDeleting(properties);
            try
            {
                Common.Utilities.ClearCache("listName");
            }
            catch (Exception ex)
            {
                // TODO: Add Error Handling ?? Should be a pretty safe Operation I would think...
            }
        }

        public override void ItemUpdating(SPItemEventProperties properties)
        {
            base.ItemUpdating(properties);
            try
            {
                Common.Utilities.ClearCache("listName");
            }
            catch (Exception ex)
            {
                // TODO: Add Error Handling ?? Should be a pretty safe Operation I would think...
            }
        }
    }
}
